package com.zyz.K_集合.List接口实现类二LinkedList;

import java.util.Iterator;
import java.util.LinkedList;

/**
 * @author: vick
 * @Date: 2025/3/28
 * @Description:
 * @version: 1.0
 */
public class Test {
    public static void main(String[] args) {
        LinkedList linkedList = new LinkedList();
        linkedList.add("aaa");
        linkedList.add("bbb");
        linkedList.add("ccc");
        linkedList.add("ddd");
        System.out.println(linkedList);

        //大小
        int size = linkedList.size();
        System.out.println(size);

        Iterator iterator = linkedList.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

        //获取
        Object object = linkedList.get(2);
        System.out.println(object);
        System.out.println(linkedList.getFirst());
        System.out.println(linkedList.getLast());

        //头部添加
        linkedList.addFirst("eee");
        System.out.println(linkedList);
        linkedList.offerFirst("fff");
        System.out.println(linkedList);

        //删除第一个
        linkedList.remove();
        System.out.println(linkedList);
        linkedList.pollFirst();
        System.out.println(linkedList);

        //删除最后一个元素
        linkedList.removeLast();
        System.out.println(linkedList);
        linkedList.pollLast();
        System.out.println(linkedList);

        //删除指定元素
        linkedList.remove("aaa");
        System.out.println(linkedList);
    }
}
